package cn.edu.sdjzu.xg.eagle.controller;


import cn.edu.sdjzu.xg.eagle.entities.Material;
import cn.edu.sdjzu.xg.eagle.service.impl.MaterialImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.List;

@RestController
@RequestMapping("material")
public class MaterialController {
    @Autowired
    private MaterialImpl materialService;

    @PostMapping
    public String addMaterial(@RequestBody Material material) throws SQLException {
        return materialService.addMaterial(material);
    }

    @DeleteMapping("/{id}")
    public String deleteMaterial(@PathVariable int id) throws SQLException {
        return materialService.deleteMaterial(id);
    }

    @PutMapping
    public String updateMaterial(@RequestBody Material material) throws SQLException {
        return materialService.updateMaterial(material);
    }

    @GetMapping("/{id}")
    public Material getMaterial(@PathVariable int id) throws SQLException {
        return materialService.findMaterialById(id);
    }

    @GetMapping
    public List<Material> getAllMaterials() throws SQLException {
        return materialService.findMaterials();
    }
}
